using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Data;

namespace Ricciolo.PaperBoy.UI.Converters
{
    public class DefaultStringConverter : IValueConverter
    {
        private const int MaxChars = 20;

        #region IValueConverter Members

        object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string s;
            if (String.IsNullOrEmpty(value as String))
                s = parameter as String;
            else
                s = value as String;
            //if (value as Feeds.FeedItem == null && String.IsNullOrEmpty(value as String))
            //    return parameter as String;
            //else if (value is Feeds.FeedItem)
            //{
            //    string s = ((Feeds.FeedItem)value).Title;
            //}
            //else
            //    return value as String;
            if (s.Length > MaxChars)
                s = s.Substring(0, MaxChars) + "...";
            return s;

        }

        object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        #endregion
    }
}
